package com.czkt.springboot_mybatis_test.controller;


import com.czkt.springboot_mybatis_test.entity.BasDict;
import com.czkt.springboot_mybatis_test.entity.CstLost;
import com.czkt.springboot_mybatis_test.entity.Page;
import com.czkt.springboot_mybatis_test.entity.vo.CstCustomerBasDict;
import com.czkt.springboot_mybatis_test.service.ICstLostService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2024-06-18
 */
@Controller
@RequestMapping("/springboot_mybatis_test/cst-lost")
public class CstLostController {
    @Resource
    ICstLostService cstLostService;

    @RequestMapping("/crm/lost/list")
    public String cstLostShow(String lstCustName, String lstCustManagerName, Integer pageIndex, Model model){
        if(pageIndex == null){
            pageIndex = 1;
        }
        Page page = new Page();

        if(lstCustName == null){
            lstCustName = "";
        }
        if(lstCustManagerName == null){
            lstCustManagerName = "";
        }
        Integer count = cstLostService.cstLostCount(lstCustName, lstCustManagerName);
        if(count == 0){
            count = 1;
        }
        page.setTotalCount(count);
        if(pageIndex < 1){
            pageIndex = 1;
        }
        if(pageIndex > page.getTotalPageCount()){
            pageIndex = page.getTotalPageCount();
        }
        int index = (pageIndex - 1) * page.getPageSize();
        page.setPageNo(pageIndex);

        List<CstLost> cstLostList = cstLostService.selectCstLost(lstCustName, lstCustManagerName,index,page.getPageSize());
        page.setCstLostList(cstLostList);
        model.addAttribute("rolePage",page);
        model.addAttribute("lstCustName",lstCustName);
        model.addAttribute("lstCustManagerName",lstCustManagerName);
        return "/lost/list";
    }
}
